package com.echat.elocation.manager;

import android.app.Activity;

import java.util.ArrayList;

/**
 *
 * @author lihao
 *
 * @date 2018/7/11 9:49
 */
public class ActivityCollector {

    private static ArrayList<Activity> activities = new ArrayList<>();

    public static void addActivity(Activity activity){
        activities.add(activity);
    }

    public static void removeActivity(Activity activity){
        activities.remove(activity);
    }

    public static void finishAll(){
        for (Activity activity : activities){
            if(!activity.isFinishing()){
                activity.finish();
            }
        }
        // 关闭当前进程
        android.os.Process.killProcess(android.os.Process.myPid());
    }

    /**
     * 获取栈顶的 Activity
     * @return
     */
    public static Activity getTopActivity(){
        if(activities.isEmpty()) {
            return null;
        }
        return activities.get(activities.size() - 1);
    }
}
